import request from "@/utils/request";
import { AxiosPromise } from "axios";
import {CategoryForm, CategoryOptions, CategoryPage, CategoryQuery} from "./types";

/**
 * 获取分页列表
 *
 * @param queryParams
 */
export function getCategoryPage(
  queryParams: CategoryQuery
): AxiosPromise<PageResult<CategoryPage[]>> {
  return request({
    url: "/admin/category/index",
    method: "get",
    params: queryParams,
  });
}

export function getOptions(): AxiosPromise<CategoryOptions[]> {
  return request({
    url: "/admin/category/getOptions",
    method: "get",
  });
}
/**
 * 获取表单详情
 *
 * @param ids
 */
export function getCategoryForm(ids: number): AxiosPromise<CategoryForm> {
  return request({
    url: "/admin/category/edit",
    method: "get",
    params: {
      ids: ids,
    },
  });
}

/**
 * 添加
 *
 * @param data
 */
export function addCategory(data: any) {
  return request({
    url: "/admin/category/add",
    method: "post",
    data: data,
  });
}

/**
 * 修改
 *
 * @param id
 * @param data
 */
export function updateCategory(data: CategoryForm) {
  return request({
    url: "/admin/category/edit",
    method: "put",
    data: data,
  });
}

/**
 * 删除
 *
 * @param data
 */
export function deleteCategory(data: any) {
  return request({
    url: "/admin/category/del",
    method: "delete",
    data,
  });
}

